package com.example.manualexchangemultipledatasourcedemo.jobs;

import com.example.manualexchangemultipledatasourcedemo.service.ConsumerService;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

/**
 * @author yj
 * @since 2020/9/14
 */
// 分布式环境下不可并发执行
@DisallowConcurrentExecution
public class BackDataJob extends QuartzJobBean {

    private static final Logger LOG = LoggerFactory.getLogger(BackDataJob.class);
    private final ConsumerService consumerService;

    @Autowired
    public BackDataJob(ConsumerService consumerService) {
        this.consumerService = consumerService;
    }
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        LOG.info("BackDataJob Starting...");

        consumerService.AddAndRemoveData();

        LOG.info("BackDataJob End");
    }
}
